/*
 * @Author: your name
 * @Date: 2021-10-19 14:10:44
 * @LastEditTime: 2021-10-22 13:54:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Vuec:\Users\86131\Desktop\project\payforknowledge\src\router\index.js
 */
import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/index",
      },
      {
        path: "/home/index",
        component: () => import("../views/Home/index.vue"),
        // children: [
        //   {
        //     path: "/home/index",
        //     redirect: "/inClass"
        //   },
        //   {
        //     path: "/home/index/inClass",
        //     component: () => import("../views/Home/indextabr/inClasss.vue")
        //   },
        //   {
        //     path: "/home/index/inElectronicBook",
        //     component: () => import("../views/Home/indextabr/inElectronicBook.vue")
        //   }
        // ]
      },
      {
        path: "/home/message",
        component: () => import("../views/Home/message.vue"),
      },
      {
        path: "/home/shopcar",
        component: () => import("../views/Home/shopcar.vue"),
        meta: { requiresAuth: true },
      },
      {
        path: "/home/mine",
        component: () => import("../views/Home/mine.vue"),
      },
    ],
  },
  {
    path: "/grabble",
    component: () => import("../views/grabble.vue"),
  },
  {
    path: "/login",
    component: () => import("../views/login.vue"),
  },
  {
    path: "/register",
    component: () => import("../views/register.vue"),
  },
  {
    path: "/detail",
    component: () => import("../views/detail.vue"),
  },
  {
    path: "/class",
    component: () => import("../views/class.vue"),
  },
  {
    path: "/classDetail",
    component: () => import("../views/classDetail.vue"),
  },
  {
    path: "/courseDescription",
    component: () => import("../views/courseDescription.vue"),
  },
  {
    path: "/classVideo",
    component: () => import("../views/classVideo.vue"),
  },
  {
    path: "/listenAudio",
    component: () => import("../views/listenAudio.vue"),
  },
  {
    path: "/electronicBook",
    component: () => import("../views/electronicBook.vue"),
  },
  {
    path: "/electronicAudio",
    component: () => import("../views/electronicAudio.vue"),
  },
  {
    path: "/pay",
    name: "pay",
    component: () => import("../views/pay.vue"),
  },
  {
    path: "/play",
    component: () => import("../views/play.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth) {
    if (localStorage.getItem("token")) {
      next();
    } else {
      next("/login");
    }
  } else {
    next();
  }
});
export default router;
